/*
 * $Id$
 *
 * Copyright ( c ) 2014 TH Supcom Corporation. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of TH Supcom
 * Corporation ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with TH Supcom Corporation or a TH Supcom
 * authorized reseller (the "License Agreement"). TH Supcom may make changes to the
 * Confidential Information from time to time. Such Confidential Information may
 * contain errors.
 *
 * EXCEPT AS EXPLICITLY SET FORTH IN THE LICENSE AGREEMENT, TH Supcom DISCLAIMS ALL
 * WARRANTIES, COVENANTS, REPRESENTATIONS, INDEMNITIES, AND GUARANTEES WITH
 * RESPECT TO SOFTWARE AND DOCUMENTATION, WHETHER EXPRESS OR IMPLIED, WRITTEN OR
 * ORAL, STATUTORY OR OTHERWISE INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A
 * PARTICULAR PURPOSE. TH Supcom DOES NOT WARRANT THAT END USER'S USE OF THE
 * SOFTWARE WILL BE UNINTERRUPTED, ERROR FREE OR SECURE.
 *
 * TH Supcom SHALL NOT BE LIABLE TO END USER, OR ANY OTHER PERSON, CORPORATION OR
 * ENTITY FOR INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL
 * DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR USE, WHETHER IN AN
 * ACTION IN CONTRACT, TORT OR OTHERWISE, EVEN IF TH Supcom HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES. TH Supcom' TOTAL LIABILITY TO END USER SHALL NOT
 * EXCEED THE AMOUNTS PAID FOR THE TH Supcom SOFTWARE BY END USER DURING THE PRIOR
 * TWELVE (12) MONTHS FROM THE DATE IN WHICH THE CLAIM AROSE.  BECAUSE SOME
 * STATES OR JURISDICTIONS DO NOT ALLOW LIMITATION OR EXCLUSION OF CONSEQUENTIAL
 * OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO END USER.
 *
 * Copyright version 2.0
 */
package com.th.supcom.pds.impl.service.internal.config;

import net.carefx.framework.exception.BusinessException;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.th.supcom.pds.domain.pojo.PhamWindowConfig;

/**
 *
 */
public final class PhamWindowUtils
{
    /** 日志记录器. */
    public static final Logger s_logger = LoggerFactory.getLogger (PhamWindowUtils.class);

    private PhamWindowUtils ()
    {

    }

    /**
     * 校验窗口属性配置
     * 
     * @param phamWindowConfig
     */
    public static void checkWindowConfig (PhamWindowConfig phamWindowConfig)
    {
        if (StringUtils.isEmpty (phamWindowConfig.getWindowIp ()))
        {
            throw new IllegalArgumentException ("保存药房窗口属性列表时，IP地址不能为空");
        }
        if (StringUtils.isEmpty (phamWindowConfig.getWindowName ()))
        {
            throw new IllegalArgumentException ("保存药房窗口属性列表时，窗口名称不能为空");
        }
        if (StringUtils.isEmpty (phamWindowConfig.getDeptCode ()))
        {
            throw new IllegalArgumentException ("保存药房窗口属性列表时，药房编码不能为空");
        }
        if (StringUtils.isEmpty (phamWindowConfig.getServiceType ()))
        {
            throw new IllegalArgumentException ("保存药房窗口属性列表时，服务类型不能为空");
        }
        if (null == phamWindowConfig.getOpenFlag ())
        {
            throw new IllegalArgumentException ("保存药房窗口属性列表时，开放标识不能为空");
        }
    }

    /**
     * 校验数据库中是否已存在当前药房窗口配置
     * 
     * @param phamWindowConfig
     * @param isAdd 添加时，true；更新时，false
     */
    public static void checkPhamWindowConfigExistence (PhamWindowConfig phamWindowConfig, boolean isAdd, int windowCount)
    {
        if (isAdd)
        {
            if (windowCount != 0)
            {
                throw new BusinessException ("该药房窗口属性配置已存在");
            }
            return;
        }
        if (windowCount > 1)
        {
            throw new BusinessException ("该药房机器属性配置已存在");
        }
    }

    /**
     * 校验当前窗口分配IP地址已被占用
     * 
     * @param phamWindowConfig
     * @param isAdd 添加时，true；更新时，false
     */
    public static void checkPhamWindowIPExistence (PhamWindowConfig phamWindowConfig, boolean isAdd, int ipCount)
    {
        if (isAdd)
        {
            if (ipCount != 0)
            {
                throw new BusinessException ("该药房窗口分配ip已被占用！");
            }
            return;
        }
        if (ipCount > 1)
        {
            throw new BusinessException ("该药房窗口分配ip已被占用！");
        }
    }

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, XuNuo Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";
}
